package com.hakim.wfb.admin.service.impl;

import com.hakim.wfb.admin.params.customer.GetCustomerOrderListPageParam;
import com.hakim.wfb.admin.params.customer.SendCustomerOrderParameter;
import com.hakim.wfb.admin.result.admin.CustomerOrderListView;
import com.hakim.wfb.admin.service.api.OrderService;
import com.hakim.wfb.customer.params.order.SignOrderParameter;
import com.hakim.wfb.dao.OrderListDao;
import com.hkfs.fundamental.api.data.ListResultEx;
import com.hkfs.fundamental.api.data.ResultEx;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 */
@Service("adminOrderService")
public class OrderServiceImpl implements OrderService {

    @Autowired
    private OrderListDao orderListDao;

    @Override
    public ListResultEx<CustomerOrderListView> getCustomerOrderList(GetCustomerOrderListPageParam param) {
        ListResultEx<CustomerOrderListView> reList = new ListResultEx<>();
        try {
            List<CustomerOrderListView> res = orderListDao.getCustomerOrderList(param);
            reList.setDataList(res);
            reList.setTotalCount(orderListDao.getCustomerOrderListCount(param));
        } catch (Exception e) {
            return reList.makeFailedResult("查询出错");
        }
        return reList.makeSuccessResult();
    }

    @Override
    public ResultEx sendOrder(SendCustomerOrderParameter param) {
        ResultEx re = new ResultEx();
        try {
            orderListDao.adminSend(param);
            re.makeSuccessResult();
        } catch (Exception e) {
            return re.makeFailedResult("操作失败");
        }
        return re;
    }

    @Override
    public ResultEx signOrder(SignOrderParameter parameter) {
        ResultEx re = new ResultEx();
        try {
            orderListDao.adminSign(parameter);
            re.makeSuccessResult();
        } catch (Exception e) {
            return re.makeFailedResult("操作失败");
        }
        return re;
    }

}
